package com.example.testapp.activity.activity.menu;

import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.Toast;

import com.example.testapp.R;

import java.util.Calendar;

/**
 * Created by l on 2016/6/29.
 */
public class TimeActivity extends AppCompatActivity {

    private Button  mTimeBtn, mDateBtn, mTimerBtn;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time);

        initView();
    }

    private void initView() {
        mTimeBtn = (Button)findViewById(R.id.btnTimeDialog);
        mDateBtn = (Button)findViewById(R.id.btnDateDialog);
        mTimerBtn = (Button)findViewById(R.id.btnTime);
        mTimeBtn.setOnClickListener(mOnClickListener);
        mDateBtn.setOnClickListener(mOnClickListener);
        mTimerBtn.setOnClickListener(mOnClickListener);
    }

    private View.OnClickListener mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.btnTimeDialog:
                    TimePickerDialog time = new TimePickerDialog(TimeActivity.this, new TimePickerDialog.OnTimeSetListener(){

                        @Override
                        public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                            Toast.makeText(TimeActivity.this, hourOfDay+"hour"+minute+"minute", Toast.LENGTH_SHORT).show();
                        }
                    }, Calendar.HOUR_OF_DAY, Calendar.MINUTE, true);
                    time.show();
                    break;
                case R.id.btnDateDialog:
                    final DatePickerDialog date = new DatePickerDialog(TimeActivity.this, new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                            Toast.makeText(TimeActivity.this, year+"year"+monthOfYear+"monthOfYear"+dayOfMonth+"dayOfMonth", Toast.LENGTH_SHORT).show();
                        }
                    }, Calendar.YEAR, Calendar.MONTH, Calendar.DAY_OF_MONTH);
                    date.show();
                    break;
                case R.id.btnTime:
                    startActivity(new Intent(TimeActivity.this, DateTimeActivity.class));
                    break;
            }
        }
    };
}
